<?php
final class XFileAppender{
	protected $file = null;
	protected $handler = null;
	
	public function __construct(XFile $file){
		$this->file = $file;
		$this->handler = @fopen($file->getPath(), 'a+');
		if($this->handler
			&& !@flock($this->handler, LOCK_EX)){
			@fclose($this->handler);
			$this->handler = null;
		}
	}
	
	public function append($content){
		if(!$this->ready()){
			return false;
		}
		return @fwrite($this->handler, $content);			
	}
	
	public function close(){
		if($this->ready()){
			@flock($this->handler, LOCK_UN);
			@fclose($this->handler);
			$this->handler = null;
		}
	}
		
	public function ready(){
		return !is_null($this->handler) && $this->handler !== false;
	}
}
?>